@extends('admin.base')
@section('title', '角色列表')
@section('content')
<div class="layui-card">
    <fieldset class="layui-elem-field">
        <div class="layui-field-box">
            <span class="layui-breadcrumb" lay-separator=">>">
                <a class="layui-btn-sm" href="{{url('admin/role/index')}}" style="cursor:pointer;" >角色列表</a>;
                <a class="layui-btn-sm" href="" style="cursor:pointer;" ><cite>编辑</cite></a>
                <!-- <a><cite>正文</cite></a> -->
            </span>
        </div>
    </fieldset>

    <form class="layui-form layui-form-pane" method="post" action="" enctype="multipart/form-data" >
        @csrf
        <input type="hidden" name="id" value="{{$res['id']}}">
        <div class="layui-form-item">
            <label class="layui-form-label">角色名</label>
            <div class="layui-input-inline">
                <input type="text" name="name" value="{{$res['name']}}" required  lay-verify="required" maxlength="50" placeholder="请输入角色名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text" >
            <label class="layui-form-label">说明</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入内容/200字以内" maxlength="200" class="layui-textarea">{{$res['remark']}}</textarea>
            </div>
        </div>
        <blockquote class="layui-elem-quote">
          <b>权限</b>
        </blockquote>
        @foreach ($nodeList as $v)
            <div class="layui-form-item" pane>
                <label class="layui-form-label">{{$v['name']}}</label>
                <div class="layui-input-block">
                    @foreach ($v['nodes'] as $sv)
                        <!-- <input type="checkbox" name="role[]" value="{{$sv['id']}}" title="{{$sv['label']}}" lay-skin="primary" > -->
                        <input type="checkbox" name="node[]" value="{{$sv['id']}}" title="{{$sv['label']}}" @if( in_array($sv['id'],$nodes) || in_array($sv['name'],$nodeDefArr) ) checked @endif >
                    @endforeach
                </div>
            </div>
        @endforeach
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
@endsection
@section('js')
    <script>
        //Demo
        layui.use('form', function(){
            var form = layui.form;
            form.render();
            //监听提交
            form.on('submit(formDemo)', function(data){
                layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){
                    ajax("{{url('admin/role/update')}}",data.field, function(data){
                        layer.close();
                        layer.closeAll();
                        layer.msg(data.msg);
                        if(data.code == 1){
                            location.href = '/admin/role/index';
                        }
                    });
                });
                return false;
            });
        });
    </script>
@endsection
